<?php

namespace App\Models\Common;

use App\Models\BaseModel;
use App\Models\OpenShop\SiteLocation\OpenShopSiteLocationExamineLogModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class MapNationalBrandShopModel extends BaseModel
{
    use HasFactory;

    protected $table = "map_national_brand_shop";

    protected $fillable = [
        'wgNumber',
        'brand',
        'name',
        'lon',
        'lat',
        'status',
        'type',
        'address',
        'province',
        'city',
        'district',
        'openingTime',
        'star',
    ];

    protected $appends = [
        'nameText',
        'lng'
    ];

    const COMPETITIVE_PRODUCTS = 1;  //竞品
    const COMPLEMENTARY_PRODUCTS = 2;  //互补品

    public function logRel(): HasMany
    {
        return $this->hasMany(OpenShopSiteLocationExamineLogModel::class, 'orderNo', 'wgNumber');
    }

    public function resourceWithMapRel(): HasOne
    {
        return $this->hasOne(ResourcesModel::class, 'name', 'wgNumber')->where('module', ResourcesModel::MODULE_TYPE_WG_AUDIT)->where('business', ResourcesModel::BUSINESS_WG_AUDIT);
    }

    /**
     * 定义一个访问器
     */
    public function getNameTextAttribute()
    {
        return $this->name;
    }

    /**
     * 定义一个访问器
     */
    public function getLngAttribute()
    {
        return $this->lon;
    }

}
